package com.product.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.product.dao.EquityDetailedDao;
import com.product.entity.EquityDetailed;
import com.product.service.IEquityDetailed;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @program: Member_Perks_Store
 * @description:
 * @author: 无恙
 * @create: 2024-06-18 15:39
 **/

@Service
public class IEquityDetailedImpl extends ServiceImpl<EquityDetailedDao, EquityDetailed> implements IEquityDetailed {

    private EquityDetailedDao equityDetailedDao;
    @Autowired
    public void setEquityDetailedDao(EquityDetailedDao equityDetailedDao) {
        this.equityDetailedDao = equityDetailedDao;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateInventory(Long Id, int quantity) {
        //查询权益商品信息详情表ID
        EquityDetailed equityDetailed = equityDetailedDao.selectById(Id);
        //更新库存
        equityDetailed.setRemainingStock(equityDetailed.getRemainingStock() - quantity);
        equityDetailedDao.updateById(equityDetailed);

        return equityDetailed.getRemainingStock();

    }



}
